<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目">
              <a-input placeholder="请输入项目名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备编号">
              <a-input placeholder="请输入设备编号" v-model="queryParam.serialNo"></a-input>
            </a-form-item>
          </a-col>
        <!--  <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="平台账号APP开发者">
              <a-input placeholder="请输入平台账号APP开发者" v-model="queryParam.appId"></a-input>
            </a-form-item>
          </a-col>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备名称">
              <a-input placeholder="请输入设备名称" v-model="queryParam.address"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
           <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="设备地址">
                <a-input placeholder="请输入设备地址" v-model="queryParam.address"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="设备状态">
                <j-dict-select-tag placeholder="请选择设备状态" v-model="queryParam.status" dictCode="sm_message_status"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="设备开门信号">
                <a-input placeholder="请输入设备开门信号" v-model="queryParam.doorSignal"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="设备开门延迟时间">
                <a-input placeholder="请输入设备开门延迟时间" v-model="queryParam.doorDelay"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="推送http地址">
                <a-input placeholder="请输入推送http地址" v-model="queryParam.pushUrl"></a-input>
              </a-form-item>
            </a-col>-->
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否强制更新">
                <j-dict-select-tag placeholder="请选择是否强制更新" v-model="queryParam.upgrade" dictCode="sm_app_upgrade"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="升级时间">
                <j-date placeholder="请选择升级时间" v-model="queryParam.upgradeTime"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否成功">
                <j-dict-select-tag placeholder="请选择是否成功" v-model="queryParam.isSuccess" dictCode="sm_upgraue_status"/>
              </a-form-item>
            </a-col>

            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="类型">
                <j-dict-select-tag placeholder="请选择类型" v-model="queryParam.atype" dictCode="sm_device_type"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
     <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('facedevice')">导出</a-button>
       <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
         <a-button type="primary" icon="import">导入</a-button>
       </a-upload>
       &lt;!&ndash; 高级查询区域 &ndash;&gt;
       <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <a-dropdown v-if="selectedRowKeys.length > 0">
       <!-- <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>-->
        <a-menu slot="overlay" @click="handleMenuClick">
          <a-menu-item key="1">
            <a-icon  @click="batchLable('1')"/>
            强制更新版本
          </a-menu-item>

        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <facedevice-modal ref="modalForm" @ok="modalFormOk"></facedevice-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import FacedeviceModal from './modules/FacedeviceModal'
  import {lableUpdateBatch} from '@/api/api'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'

  export default {
    name: 'FacedeviceList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      FacedeviceModal
    },
    data () {
      return {
        description: 'facedevice管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'项目',
            align:"center",
            dataIndex: 'projectName'
          },
          {
            title:'设备编号',
            align:"center",
            dataIndex: 'serialNo'
          },
         /* {
            title:'平台账号APP开发者',
            align:"center",
            dataIndex: 'appId'
          },*/
          {
            title:'设备名称',
            align:"center",
            dataIndex: 'address'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'atype_dictText'
          },
          {
            title:'设备状态',
            align:"center",
            dataIndex: 'status_dictText'
          },
        /*  {
            title:'设备开门信号',
            align:"center",
            dataIndex: 'doorSignal'
          },
          {
            title:'设备开门延迟时间',
            align:"center",
            dataIndex: 'doorDelay'
          },
          {
            title:'设备开门方式',
            align:"center",
            dataIndex: 'doorMode'
          },
          {
            title:'设备识别的阈值',
            align:"center",
            dataIndex: 'threshold'
          },
          {
            title:'设备推送WEBSOCKET URL地址',
            align:"center",
            dataIndex: 'pushWebsocketUrl'
          },
          {
            title:'设备推送的MQTT地址',
            align:"center",
            dataIndex: 'pushMqttUrl'
          },
          {
            title:'推送http地址',
            align:"center",
            dataIndex: 'pushUrl'
          },
          {
            title:'设备型号',
            align:"center",
            dataIndex: 'model'
          },
          {
            title:'设备人脸数量',
            align:"center",
            dataIndex: 'faceCount'
          },*/
        /*  {
            title:'设备类型',
            align:"center",
            dataIndex: 'deviceType_dictText'
          },*/
          {
            title:'当前版本号',
            align:"center",
            dataIndex: 'version'
          },
          {
            title:'最新版本号',
            align:"center",
            dataIndex: 'nversion'
          },
          {
            title:'是否强制更新',
            align:"center",
            dataIndex: 'upgrade_dictText'
          },
          {
            title:'升级时间',
            align:"center",
            dataIndex: 'upgradeTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'是否成功',
            align:"center",
            dataIndex: 'isSuccess_dictText'
          },

          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/smzh/facedevice/list",
          delete: "/smzh/facedevice/delete",
          deleteBatch: "/smzh/facedevice/deleteBatch",
          exportXlsUrl: "/smzh/facedevice/exportXls",
          importExcelUrl: "smzh/facedevice/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      batchLable: function (status) {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return false;
        } else {
          let ids = "";
          let that = this;
          let isAdmin = false;
          /*  that.selectionRows.forEach(function (row) {
              if (row.username == 'admin') {
                isAdmin = true;
              }
            });*/

          that.selectedRowKeys.forEach(function (val) {
            ids += val + ",";
          });
          debugger;
          let remark = "";
          if(status == 1){
            remark = "版本强制更新";
          }

          that.$confirm({
            title: "确认操作",
            //content: "选中数据是否批量变更为?",
            content: "选中数据是否批量变更为" + remark+ "?",
            onOk: function () {
              lableUpdateBatch({ids: ids, status: status}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              });
            }
          });
        }
      },

      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'serialNo',text:'设备编号',dictCode:''})
        fieldList.push({type:'int',value:'appId',text:'平台账号APP开发者',dictCode:''})
        fieldList.push({type:'string',value:'address',text:'设备地址',dictCode:''})
        fieldList.push({type:'int',value:'status',text:'设备状态',dictCode:'sm_device_status'})
        fieldList.push({type:'string',value:'doorSignal',text:'设备开门信号',dictCode:''})
        fieldList.push({type:'int',value:'doorDelay',text:'设备开门延迟时间',dictCode:''})
        fieldList.push({type:'string',value:'doorMode',text:'设备开门方式',dictCode:''})
        fieldList.push({type:'int',value:'threshold',text:'设备识别的阈值',dictCode:''})
        fieldList.push({type:'string',value:'pushWebsocketUrl',text:'设备推送WEBSOCKET URL地址',dictCode:''})
        fieldList.push({type:'string',value:'pushMqttUrl',text:'设备推送的MQTT地址',dictCode:''})
        fieldList.push({type:'string',value:'pushUrl',text:'推送http地址',dictCode:''})
        fieldList.push({type:'string',value:'model',text:'设备型号',dictCode:''})
        fieldList.push({type:'int',value:'faceCount',text:'设备人脸数量',dictCode:''})
        fieldList.push({type:'int',value:'deviceType',text:'设备类型',dictCode:'sm_message_status'})
        fieldList.push({type:'string',value:'id',text:'String ',dictCode:''})
        fieldList.push({type:'string',value:'version',text:'当前版本号',dictCode:''})
        fieldList.push({type:'string',value:'newVersion',text:'最新版本号',dictCode:''})
        fieldList.push({type:'int',value:'upgrade',text:'是否强制更新 0：否 1：是',dictCode:'sm_app_upgrade'})
        fieldList.push({type:'date',value:'upgradeTime',text:'升级时间'})
        fieldList.push({type:'int',value:'isSuccess',text:'是否成功',dictCode:'sm_upgraue_status'})
        fieldList.push({type:'int',value:'atype',text:'类型',dictCode:'sm_device_type'})
        fieldList.push({type:'string',value:'nversion',text:'最新版本号',dictCode:''})
        this.superFieldList = fieldList
      },
      handleMenuClick(e) {
        debugger;
        if (e.key == 1) {
          this.batchLable(1);
        }

      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>